class Touch {
    constructor(){
        this.start = null;
        this.end = null;
        this.cx = null;
        this.cy = null;
    }
    // touchStart事件
    touchStart (e) {
        // console.log('鼠标按下',e.touches[0]);
        this.start = {
            x: e.touches[0].clientX,
            y: e.touches[0].clientY
        }
    }
    // touchMove事件
    touchMove (e,ele) {
        this.end = {
            x: e.touches[0].clientX,
            y: e.touches[0].clientY
        }
        
        this.cx = this.end.x - this.start.x;
        this.cy = this.end.y - this.start.y; 
        if(Math.abs(this.cx) < Math.abs(this.cy)){
            var directionL = this.cy > 0?'下':'上';
            if(directionL === '上'){
                ele.current.style.transition= `all 2s linear`
                ele.current.style.transform = `translateY(${e.touches[0].clientY - this.start.y}px)`
            }else if(directionL === '下'){
                ele.current.style.transition= `all .3s linear`
                ele.current.style.transform = `translateY(${e.touches[0].clientY/5}px)`
            }
        }
    }
    // touchEnd事件
    touchEnd (e,ele) {
        // 鼠标抬起的时候让盒子回到最顶部
        ele.current.style.transition= `all 1s ease`
        ele.current.style.transform = `translateY(0px)`
    }
}    

export default new Touch()